(function (global, factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        module.exports = factory(global, true)
    } else {
        factory(global)
    }
})(typeof window !== "undefined" ? window : this, function (window, noGlobal) {
    class A_B {
        constructor(obj) {
            this.timer
            this.in_a = false
            this.in_b = false
            this.a = document.getElementById(obj.a_id)
            this.b = document.getElementById(obj.b_id)
            this.init()
        }
        // 隐藏b
        hide_b() {
            let that = this
            clearTimeout(that.timer)
            // 正常情况下若既不在a上也不在b上则在1秒后消失
            this.timer = setTimeout(() => {
                if (!that.in_a && !that.in_b) {
                    that.b.style.display = "none"
                }
            }, 1000);
        }
        init() {
            let that = this
            this.b.style.display = "none"

            this.a.onmouseover = function () {
                clearTimeout(that.timer)
                this.in_a = true
                that.b.style.display = "block"
            }
            this.a.onmouseout = function () {
                this.in_a = false
                that.hide_b(that.timer)
            }
            this.b.onmouseover = function () {
                clearTimeout(that.timer)
                this.in_b = true
                that.b.style.display = "block"
            }
            this.b.onmouseout = function () {
                this.in_b = false
                that.hide_b(that.timer)
            }

        }

    }
    if (typeof noGlobal === "undefined") {
        window.A_B = A_B
    }
    return A_B
})